package com.savi.myapplication.adapter;


import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;

//import com.vp.myapplication.E;
import com.savi.myapplication.R;
//import com.vp.application.datastruct.FlyCardInfo;
//import com.vp.application.datastruct.FlyCardTemplate;
//import com.vp.application.fly.FlyCardActivity;

import com.savi.myapplication.EFBGlobalData;
import com.savi.myapplication.FlyCardActivity;
import com.savi.myapplication.fragment.FlyTimeFragment;
import com.savi.myapplication.model.FlyCardInfo;
import com.savi.myapplication.model.FlyCardTemplate;

import java.util.UUID;

public class AddFlyCardPopupWindow extends PopupWindow implements  View.OnClickListener {




    private EFBGlobalData g_App;
    private FlyCardActivity activity;
    private Button m_btnOK, m_btnCancel;
    private EditText m_etTaskName;

    private FlyTimeFragment flyTimeFragment;
    public AddFlyCardPopupWindow(FlyCardActivity activity, View contentView, int width, int height, int locX, int locY,
                                 boolean focusable) {
        super(contentView, width, height, focusable);
        this.setBackgroundDrawable(new BitmapDrawable());
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        this.showAtLocation(contentView, Gravity.CENTER, locX, locY);




        g_App = (EFBGlobalData) activity.getApplicationContext();

        this.activity = activity;
//        this.flyTimeFragment = flyTimeFragment;

        initView();
        initData();
    }

    /**
     * 初始化布局文件
     */
    private void initView() {

//        getContentView().findViewById(R.id)

        m_etTaskName = getContentView().findViewById(R.id.et_taskcard_name);
        m_btnOK = getContentView().findViewById(R.id.btn_task_card_ok);
        m_btnCancel = getContentView().findViewById(R.id.btn_task_card_cancel);
//
    }

    /**
     * 初始化数据
     */
    public void initData() {
//
        m_btnOK.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View view) {

                String taskCardName = m_etTaskName.getText().toString();
                if (!taskCardName.isEmpty()){

                    FlyCardInfo flyCardInfo = new FlyCardInfo();
                    FlyCardTemplate flyCardTemplate = new FlyCardTemplate();
                    flyCardInfo.setCardUUid(UUID.randomUUID().toString());
                    flyCardInfo.setStrCardName(taskCardName);
                    flyCardInfo.setFlyCardTemplate(flyCardTemplate);

                    //将内容添加到数据库
//                    g_App.m_MFBdb.addMFB_TASK_FLY(flyCardInfo);

//                    activity.getFlyCardInfoList().add(flyCardInfo);
//                    activity.getFlyTaskCardDataLeftAdatper().setFlyCardInfoList(activity.getFlyCardInfoList());
//                    activity.getFlyTaskCardDataLeftAdatper().notifyDataSetChanged();
//
//                    通知左侧界面显示状态
//                    activity.setViewVisibility();
                }
                dismiss();

            }
        });
//
        m_btnCancel.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View view) {
//                listenPasswordInput.onCancalPasswordInput();
                dismiss();
            }
        });

    }


    @Override
    public void onClick(View v) {

    }
}
